package engine.logic.tips
{
	import engine.data.ModelLocator;
	import engine.data.SceneObject;
	import engine.data.View;
	import engine.data.ViewObject;
	
	import newx.com.config.StaticIni;

	public class ItemTips
	{
		private const COLOR_TABLE:Array	=	["","#ffffff'>","#1eff00'>","#0070dd'>","#a335ee'>","#ff8000'>","#e5cc80'>"];
		
		public function ItemTips()
		{
			
		}
		
		public function getStr(configID:uint, bindType : int = 0, bindStatus : int = 0,cashShopObj:Object=null):String
		{
			var nameid		:String	= StaticIni.getIniVar(configID,"NameID")
			var color		:int	= int(StaticIni.getIniVar(configID,"Color"));
			var itemtype	:String	= StaticIni.getIniVar(configID,"ItemType");
			var prof		:String	= StaticIni.getIniVar(configID,"AdaptProfType");
			var needlv		:String	= StaticIni.getIniVar(configID,"NeedLevel");
			var subItemType	:String	= StaticIni.getIniVar(configID,"SubItemType");
			var des			:String	= StaticIni.getIniVar(configID,"Description");
			//宝石的等级
			var jewel		:String	= StaticIni.getIniVar(configID,"JewelLevel");
			//是否需要爵位
			var needRank	:String	= StaticIni.getIniVar(configID,"NeedPeerageRank");
			//是否需要城堡地位
			var needStatus	:String	= StaticIni.getIniVar(configID,"NeedCastleStatus");
			//物品需要爵位等级
			var needPLevel	:int	= (int(StaticIni.getIniVar(configID,"NeedPeerageLev"))	-1) % 10 + 1;
			
			
			var bookStr		:String	= StaticIni.getSwfLangStr("Description_"+configID);
			
			var roleObj	:SceneObject=	ModelLocator.getInstance().scene.Role;
			
			//当前人物的城堡地位
			var nowRank:String	=	roleObj.GetPropertiesEx("PeerageRank")
			//当前人物的爵位
			var nowStatus:String	=	roleObj.GetPropertiesEx("CurCastleStatusId")	
			//爵位等级
			var peerageLevel:int	=	(int(	roleObj.GetPropertiesEx("PeerageLev")	)	-1) % 10 + 1;
				
			
			var str:String	=	StaticIni.getSwfLangStr(nameid);
			str				=	link_color(str,color);
			str				=	str.concat("<br>")
			//商城物品信息
			if(cashShopObj!= null)
			{
				str	=	str.concat(cashShopStr(cashShopObj));
			}
			//装备绑定
			var equitStr : String = equipBind(bindType, bindStatus) ;
			if(equitStr != "") equitStr	=	equitStr +"<br>";	
			str =	str.concat(equitStr);
			
			str				+=	StaticIni.getSwfLangStr("ItemTypeDes_"+itemtype)+"<br>";
			
			if(prof != null && prof != "")
			{
				var userProf:String	=	roleObj.GetPropertiesEx("ProfType");
				var profList:Array	=	prof.split(",");
				if(profList.indexOf(userProf)>-1)
				{
					str	+=	StaticIni.getSwfLangStr("AdaptProfType_"+prof)+"<br>";
				}else{
					str	+=	"<font color='#f00000'>"+StaticIni.getSwfLangStr("AdaptProfType_"+prof)+"</font><br>";
				}
				
			}
			
			if(needlv != null && needlv != "")
			{
				var userLevel:String	=	roleObj.GetPropertiesEx("Level");
				if(userLevel!= null && userLevel != "")
				{
					if(int(userLevel)>=int(needlv))
					{
						str	+=	StaticIni.getSwfLangStr("ItemDes_NeedLevel")+needlv+"<br>";
					}else{
						str	+=	"<font color='#f00000'>"+StaticIni.getSwfLangStr("ItemDes_NeedLevel")+needlv+"</font><br>";
					}
				}
				
			}
			
			//装备类型
			var callee		:String = StaticIni.getIniVar(configID,"Callee");
			//是技能卷轴
			if(callee == "FightScroll")
			{
				str	+=	StaticIni.getSwfLangStrVar(("UIStr_1000886"), [StaticIni.getIniVar(configID,"MaxUse")]) + "<br>";
			}
			//礼物
			if(callee == "Gift")
			{
				//人气
				var charm : int = parseInt(StaticIni.getIniVar(configID,"Charm"));
				str	+=	StaticIni.getSwfLangStr("UIStr_1001027") + StaticIni.getSwfLangStrVar(charm  > 0 ? "UIStr_1001023" : "UIStr_1001022", [Math.abs(charm)]) + "<br>";
			
				var during : int = parseInt(StaticIni.getIniVar(configID,"During"));
				str	+=	StaticIni.getSwfLangStr("UIStr_1001024") + "：" + ((during == 9999) ? StaticIni.getSwfLangStr("UIStr_1001026") : StaticIni.getSwfLangStrVar("UIStr_1001025", [during])) + "<br>";
			}
			
			//是否需要爵位
			if(needRank != null && needRank != "" && needRank != "0")
			{
//				var rankStr:String	=	StaticIni.getSwfLangStr("PeerageName_"+ (int(needRank)));
//				if(int(nowRank) < int(needRank))
//				{
//					str					= str.concat( "<font color='#f00000'>"+StaticIni.getSwfLangStrVar("UIStr_1000879",[rankStr])+"</font>");
//				}else{
//					str					= str.concat( StaticIni.getSwfLangStrVar("UIStr_1000879",[rankStr]));
//				}
//				
				var rankStr:String	=	StaticIni.getSwfLangStrVar("PeerageLvel_"+needRank,[needPLevel]);
				//StaticIni.getSwfLangStr("PeerageName_"+ (int(needRank)));
//				
				//
				if(		int(nowRank) < int(needRank) ||	
					(int(nowRank) == int(needRank) &&	(peerageLevel<needPLevel))
				)
				{
					str					= str.concat( "<font color='#f00000'>"+StaticIni.getSwfLangStrVar("UIStr_1000879",[rankStr])+"</font>");
				}else{
					str					= str.concat( StaticIni.getSwfLangStrVar("UIStr_1000879",[rankStr]));
				}
				str					= str.concat("<br>");

			}
//			//是否显示宝石等级
//			if(jewel != null && jewel !="" && jewel != "0" && subItemType == "20004")
//			{
//				var tempStr:String	=	StaticIni.getSwfLangStr("UIStr_1000539") + "Lv"+jewel
//				str					= str.concat(tempStr + "<br>");
//			}
			//是否需要一定的城堡地位
			if(needStatus != null && needStatus !="" && needStatus != "0")
			{
				var statusStr:String	=	StaticIni.getSwfLangStr("CastleStatus_"+ needStatus);
				if(int(nowStatus) > int(needStatus))
				{
					str						= str	.concat( "<font color='#f00000'>"+StaticIni.getSwfLangStrVar("UIStr_1000880",[statusStr])+"</font>");
				}else
				{
					str						= str	.concat(StaticIni.getSwfLangStrVar("UIStr_1000880",[statusStr]));
				}	
				str = str.concat("<br>");	
			}
			
			if(cashShopObj == null)
			{
				//卖只能获得金币
				var sellPrice:String		= StaticIni.getIniVar(configID,"SellPrice");
				
				if(int(sellPrice) > 0)
				{
					str = str.concat(StaticIni.getSwfLangStr("UIStr_1000296"));
					str = str.concat(sellPrice);
					str = str.concat(StaticIni.getSwfLangStr("Tips_CapitalType0"));
					str = str.concat("<br>");
				}	
			}
			
			if(des != null && des != "")
			{
				str	+=	"<font color='#ffff00'>" + StaticIni.getSwfLangStr("Description_"+configID) + "</font>";
				str = str.concat("<br>");
			}else
			{
				if(bookStr!=null&&bookStr!="")
				{
					str	+=	"<br/>"+bookStr+"<br>";
				}
			}
			
			return str;
		}
		
		/**
		 *	道具是否bind 
		 * @return 
		 * 
		 */
		
		private function equipBind(bindType : int, bindStatus : int) : String
		{
			//没有绑定类型，说明不需要显示
			var t:int = 0;
			if(bindType == 0) return "";
			
			//已经绑定
			if(bindStatus == 1) return StaticIni.getSwfLangStr("BindStatus_1");
			
			return StaticIni.getSwfLangStr("BindType_" + bindType);
		}
		/**
		 * 显示商城销售商品信息 
		 * @param val
		 * @return 
		 * 
		 */		
		private function cashShopStr(val:Object):String
		{
			var tempStr:String	=	"";
			if(val != null)
			{
				//原价
				var price:int			=	val["Price"];
				//现价
				var sellprice:int		=	val["Sellprice"];
				//币种
				var cointype:int		=	val["Cointype"]
				//优惠类型
				var type:int			=	val["Type"];
				//优惠信息
				var typeref:int			=	val["Typeref"];
				//限购数量
				var limit:int			=	val["Limit"];
				//单人限购数量
				var personal:int		=	val["Personal"];
				//说明
				var desc:String			=	val["Desc"];
				
				tempStr	=	tempStr.concat(StaticIni.getSwfLangStr("UIStr_1000926") + String(price) + moneyType(cointype) + "<br>");
				tempStr	=	tempStr.concat(sellType(cointype) + String(sellprice) + moneyType(cointype) + "<br>");
				
				switch(type)
				{
					//打折
					//打折
					case 2:
						tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000961",[StaticIni.getSwfLangStr("UIStr_1000993")]) + "<br>");
						if(typeref > 0)
						{
							tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000962",[StaticIni.getSwfLangStrVar("UIStr_1000997",[typeref])]) + "<br>");			
						}
						break;
					//直降
					case 3:
						tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000961",[StaticIni.getSwfLangStr("UIStr_1000995")]) + "<br>");
						if(typeref > 0)
						{
							tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000962",[typeref + moneyType(cointype)]) + "<br>");
						}	
						break;
					//秒杀
					case 4:
						tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000961",[StaticIni.getSwfLangStr("UIStr_1000994")]) + "<br>");
						if(personal > 0)
						{
							tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000962",[StaticIni.getSwfLangStr("UIStr_1000957")+StaticIni.getSwfLangStrVar("UIStr_1000998",[personal])]) + "<br>");
						}
						break;
					//限量抢购
					case 5:
						tempStr	=	tempStr.concat(StaticIni.getSwfLangStrVar("UIStr_1000961",[StaticIni.getSwfLangStr("UIStr_1001394")]) + "<br>");
						break;
				}
//				if(desc != "" && desc != null &&desc != "11")
//				{
//					tempStr	=	tempStr.concat(desc + "<br>");
//				}
			}
			return tempStr;
		}
		
		/**
		 * 优惠类型字符
		 * @param val
		 * @return 
		 * 
		 */		
		private function sellType(val:int):String
		{
			var tempStr:String	=	"";
			switch(val){
				case 1:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000929");
					break;
				case 2:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000927");
					break;
				case 3:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000928");
					break;
				case 4:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000987");
					break;
				case 5:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000988");
					break;
				case 6:
					tempStr	=	StaticIni.getSwfLangStr("UIStr_1000929");
					break;
			}
			return tempStr;
		}
		
		public function getStrNoPrice(configID:uint):String
		{
			var nameid		:String	= StaticIni.getIniVar(configID,"NameID")
			var color		:int	= int(StaticIni.getIniVar(configID,"Color"));
			var itemtype	:String	= StaticIni.getIniVar(configID,"ItemType");
			var prof		:String	= StaticIni.getIniVar(configID,"AdaptProfType");
			var needlv		:String	= StaticIni.getIniVar(configID,"NeedLevel");
			var des			:String	= StaticIni.getIniVar(configID,"Description");
			var bookStr		:String	= StaticIni.getSwfLangStr("Description_"+configID);
			var skillID		:String	= StaticIni.getIniVar(configID,"SkillID");
			
			var str:String	=	StaticIni.getSwfLangStr(nameid);
			str				=	link_color(str,color);
			str				+=	"<br>"+StaticIni.getSwfLangStr("ItemTypeDes_"+itemtype)+"<br>";
			
			var roleObj	:SceneObject=	ModelLocator.getInstance().scene.Role;
		//	var prof:String		= StaticIni.getIniVar(configID,"AdaptProfType");
			if(prof != null && prof != "")
			{
				var userProf:String	=	roleObj.GetPropertiesEx("ProfType");
				var profList:Array	=	prof.split(",");
				temp			= StaticIni.getSwfLangStr("AdaptProfType_"+prof);
				if(profList.indexOf(userProf)>-1)
				{
					str				= str.concat(temp);
				}else{
					str				= str.concat("<font color='#f00000'>"+temp+"</font>");
				}
				str				= str.concat("<br>");
			}
			
//			if(prof != null && prof != "")
//			{
//				str	+=	StaticIni.getSwfLangStr("AdaptProfType_"+prof)+"<br>";
//			}
			
			//等级
			if(needlv != null && needlv != "")
			{	
				
				
				var temp:String				= StaticIni.getSwfLangStr("ItemDes_NeedLevel");
				var tmpStr:String	= "";
				tmpStr				= tmpStr.concat(temp);
				tmpStr				= tmpStr.concat(needlv);
				var userLevel:String	=	roleObj.GetPropertiesEx("Level");
				if(userLevel!= null && userLevel != "")
				{
					if(int(userLevel)>=int(needlv))
					{
						str				= str.concat(tmpStr);
					}else{
						str				= str.concat("<font color='#f00000'>"+tmpStr+"</font>");
					}
				}
				str				= str.concat("<br>");
			}
			
			//装备类型
			var callee		:String = StaticIni.getIniVar(configID,"Callee");
			//是技能卷轴
			if(callee == "FightScroll")
			{
				str	+=	StaticIni.getSwfLangStrVar(("UIStr_1000886"), [StaticIni.getIniVar(configID,"MaxUse")]) + "<br>";
			}
			//礼物
			if(callee == "Gift")
			{
				//人气
				var charm : int = parseInt(StaticIni.getIniVar(configID,"Charm"));
				str	+=	StaticIni.getSwfLangStr("UIStr_1001027") + StaticIni.getSwfLangStrVar(charm  > 0 ? "UIStr_1001023" : "UIStr_1001022", [Math.abs(charm)]) + "<br>";
				
				var during : int = parseInt(StaticIni.getIniVar(configID,"During"));
				str	+=	StaticIni.getSwfLangStr("UIStr_1001024") + "：" + ((during == 9999) ? StaticIni.getSwfLangStr("UIStr_1001026") : StaticIni.getSwfLangStrVar("UIStr_1001025", [during])) + "<br>";
			}
			
			if(skillID != null && skillID != "")
			{
				str	+=	checkHaveLearn(skillID);
			}
			
			if(bookStr!=null&&bookStr!="")
			{
				str	+=	bookStr;
			}
			
			return str;
		}
		
		private function checkHaveLearn(skillID:String):String
		{
			//var skillArr:Array	=	[];
			var tmpStr:String	=	"";
			var skillObj:View	=	ModelLocator.getInstance().scene.GetPropertiesEx("View4");
			skillObj.getDataForEach(function(key:String,val:*):void
			{
				if(val is ViewObject)
				{
					if(skillID==String(val.GetProperties("ConfigID")))
					{
						tmpStr	=	StaticIni.getSwfLangStr("UIStr_1000483")+"<br>";
					}
				}
			});
			
			if(tmpStr == "")
			{
				ModelLocator.getInstance().scene.GetView(View.VIEWPORT_LIFESKILL).getDataForEach(function(key:String,val:*):void
				{
					if(val is ViewObject)
					{
						if(skillID==String(val.GetProperties("ConfigID")))
						{
							tmpStr	=	StaticIni.getSwfLangStr("UIStr_1000483")+"<br>";
						}
					}
				});
			}
			return tmpStr;
		
		//VIEWPORT_LIFESKILL
		}
		
		private function link_color(str:String,color:int):String
		{
			if(color < 1 || color > 6)
			{
				color	=	1;
			}
			
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		/**
		 * 货币类型 
		 * @param val
		 * 
		 */		
		private function moneyType(val:int):String
		{
			var moneyStr:String	=	"";
			switch(val)
			{
				case 0:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType0")
					break;
				case 1:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType1")
					break;
				case 2:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType2")
					break;
				case 3:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType3")
					break;
				case 4:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType4")
					break;
				case 5:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType5")
					break;
				case 6:
					moneyStr	=	StaticIni.getSwfLangStr("Tips_CapitalType6")
					break;
			}
			return moneyStr;
		}
	}
}